<?php 

require_once 'jq-config.php'; 
// include the jqGrid Class 
require_once "php/jqGrid.php"; 
// include the driver class 
require_once "php/jqGridPdo.php"; 
// include the datepicker 
require_once "php/jqCalendar.php"; 
// Connection to the server 
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); 
// Tell the db that we use utf-8 
$conn->query("SET NAMES utf8"); 
// Create the jqGrid instance 
$grid = new jqGridRender($conn); 
// this table is 1252 encoded, so we need to tell the grid 
// Set the table data source 
//$grid->setTable('nms_domain');
$grid->SelectCommand = 'SELECT id, username, first_name, last_name, email, sex, dob, address, phone, status  FROM users';
// set the ouput format to xml since json have problems 
$grid->dataType = 'json'; 
//set a table to be manipulated
$grid->table = 'users';
// set the primary key - it is serial
$grid->setPrimaryKeyId('id');
$grid->setColModel(); 
// Set the url from where we obtain the data 
$grid->setUrl('/vnpt-qavah/database/grid.php'); 
// Set some grid options 

//get the height passed as parameter 
//$height = jqGridUtils::GetParam('gridheight', '200'); 
$grid->setGridOptions(array( 
	"rowNum"=>30, 
	"search"=>true,
	"rownumbers"=>true,
	"multiSort"=>true,
	"multiselect"=>false,
	"rowList"=>array(30,50,100), 
	"sortname"=>"customer_id",  
	"height"=>340, 
	"autoheight"=>true,
	"autowidth"=>true,
	"shrinkToFit"=> true,
	"hoverrows"=>true,
	"userDataOnFooter"=>false, 
	"footerrow"=>false,
	"cellEdit"=> false,
	"cmTemplate"=>array("sortable"=>true) 
	)); 
$grid->setColProperty('id',array("editable"=>false,));
// $grid->setColProperty("device_ip", array("resizable"=>false,"frozen"=>true,"width"=>50,"editable"=>true)); 
// $grid->setColProperty("device_name", array("resizable"=>false,"frozen"=>true,"width"=>50,"editable"=>true));
//$grid->setSelect('dist_id', "SELECT dist_id, dist_name FROM emart_customer_district"); 
// Change some property of the field(s)
// $grid->setColProperty("device_status_fail_date", array(
// 	"formatter"=>"date",
// 	"formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"Y M d"),
// 	"editable"=>true
// 	));
// $grid->setColProperty("status", array("resizable"=>false,"frozen"=>true,"width"=>20,"editable"=>true,"formatter"=>"checkbox")); 
// Date options to edit 
$grid->setUserDate("Y M d"); 
$grid->setUserTime("Y M d"); 
// $grid->setDatepicker('device_status_fail_date'); 

// $grid->datearray = array("device_status_fail_date"); 

// Enable filter toolbar searching 
$grid->toolbarfilter = true; 
// Enable operation search 
$grid->setFilterOptions(array("stringResult"=>true,"searchOperators"=>false));
// We can hide some columns 
$grid->setColProperty("id", array("hidden"=>true));
// Enable navigator
$grid->navigator = true;
// Enable excel export 
$grid->setNavOptions('navigator', array("cloneToTop"=>true,"view"=>true,"search"=>true));
$grid->setNavOptions('search', array("multipleGroup"=>true,"showQuery"=>true)); 
$grid->setNavOptions('view', array("height"=>"auto","dataheight"=>"auto")); 
$grid->setNavOptions('add', array("closeAfterAdd"=>true,"reloadAfterSubmit"=>true,"height"=>"auto","dataheight"=>"auto")); 
$grid->setNavOptions('edit', array("closeAfterEdit"=>true,"height"=>"auto","dataheight"=>"auto","editCaption"=>"Edit infromation customer","bSubmit"=>"Save")); 


// add a custom button via the build in callGridMethod 
// note the js: before the function 
$buttonoptions = array("#pager", 
	array("caption"=>"Pdf", "title"=>"Export to Pdf", "onClickButton"=>"js: function(){ 
		jQuery('#grid').jqGrid('excelExport',{tag:'pdf', url:'/eMart_Sales/assets/models/customer/device.php'});}" 
		) 
	); 
$grid->callGridMethod("#grid", "navButtonAdd", $buttonoptions); 

 
// Call the frozen cols method

// Set it to toppager 

$grid->callGridMethod('#grid', 'setFrozenColumns');
$grid->callGridMethod('#grid', 'bindKeys');
// Enjoy 
$grid->renderGrid('#grid','#pager',true, null, null, true,true); 
$conn = null; 
?>